#ifndef MRF_H
#define MRF_H

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <vector>

using namespace std;

//How many classes
#define CLASS_NUMBER 2

// How many times repeat relabeling
#define ITERATION_NUMBER 5

// Beta value for MRF energy count
#define MRF_BETA 1.5

class MRF
{
public:
	MRF(void);
	~MRF(void);
	void initLearningMRF(IplImage *img);
	void initFastMRF(IplImage *img, IplImage *labelimg);
	
	void ouputLabelledImage();

protected:
	int width, height;
	IplImage* labelImage;
	CvMat* labelMatrix;
	vector<float> means;
	vector<float> variances;
	IplImage *img;


private:
	void countMeansAndVariances();
	void defaultLabel();
	void calculateMRFWithLearning();
	void calculateMRF();
	
	float calculateEnergy(int energyClass, int i, int j);
	float calculateGibbsEnergy(int energyClass, int i, int j);
	void imageLabelFromEM(IplImage *img);

};

#endif